package com.erms.lab.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.erms.common.annotation.Log;
import com.erms.common.enums.BusinessType;
import com.erms.lab.domain.SysTrain;
import com.erms.lab.service.ISysTrainService;
import com.erms.common.core.controller.BaseController;
import com.erms.common.core.domain.AjaxResult;
import com.erms.common.utils.poi.ExcelUtil;
import com.erms.common.core.page.TableDataInfo;

/**
 * 承办培训情况Controller
 * 
 * @author guo
 * @date 2020-03-22
 */
@Controller
@RequestMapping("/lab/train")
public class SysTrainController extends BaseController
{
    private String prefix = "lab/train";

    @Autowired
    private ISysTrainService sysTrainService;

    @RequiresPermissions("lab:train:view")
    @GetMapping()
    public String train()
    {
        return prefix + "/train";
    }

    /**
     * 查询承办培训情况列表
     */
    @RequiresPermissions("lab:train:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysTrain sysTrain)
    {
        startPage();
        List<SysTrain> list = sysTrainService.selectSysTrainList(sysTrain);
        return getDataTable(list);
    }

    /**
     * 导出承办培训情况列表
     */
    @RequiresPermissions("lab:train:export")
    @Log(title = "承办培训情况", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysTrain sysTrain)
    {
        List<SysTrain> list = sysTrainService.selectSysTrainList(sysTrain);
        ExcelUtil<SysTrain> util = new ExcelUtil<SysTrain>(SysTrain.class);
        return util.exportExcel(list, "train");
    }

    /**
     * 新增承办培训情况
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存承办培训情况
     */
    @RequiresPermissions("lab:train:add")
    @Log(title = "承办培训情况", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysTrain sysTrain)
    {
        return toAjax(sysTrainService.insertSysTrain(sysTrain));
    }

    /**
     * 修改承办培训情况
     */
    @GetMapping("/edit/{traId}")
    public String edit(@PathVariable("traId") Long traId, ModelMap mmap)
    {
        SysTrain sysTrain = sysTrainService.selectSysTrainById(traId);
        mmap.put("sysTrain", sysTrain);
        return prefix + "/edit";
    }

    /**
     * 修改保存承办培训情况
     */
    @RequiresPermissions("lab:train:edit")
    @Log(title = "承办培训情况", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysTrain sysTrain)
    {
        return toAjax(sysTrainService.updateSysTrain(sysTrain));
    }

    /**
     * 删除承办培训情况
     */
    @RequiresPermissions("lab:train:remove")
    @Log(title = "承办培训情况", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysTrainService.deleteSysTrainByIds(ids));
    }
}
